package com.chzc.fm.duotin.ui.mine;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.chzc.fm.duotin.R;
import com.chzc.fm.duotin.ui.other.BaseActivity;
import com.chzc.fm.duotin.utils.NetWorkUtils;
import com.chzc.fm.duotin.widget.TitleBar;

public class ChangePwdActivity extends BaseActivity{

    private EditText editOld, editNew, editConfirm;

    private TextView textTip, textSubmit;

    private TitleBar titleBar;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_change_pwd;
    }

    @Override
    protected void initViews() {
        titleBar = (TitleBar) findViewById(R.id.title_bar);
        editOld = (EditText) findViewById(R.id.et_change_old);
        editNew = (EditText) findViewById(R.id.et_change_new);
        editConfirm = (EditText) findViewById(R.id.et_change_new_c);
        textTip = (TextView) findViewById(R.id.tv_change_tip);
        textSubmit = (TextView) findViewById(R.id.tv_change_submit);
    }

    @Override
    protected void initEvents() {
        titleBar.setLeftListener(new TitleBar.mTitleBarListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        textSubmit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String str1 = editOld.getText().toString();
                String str2 = editNew.getText().toString();
                String str3 = editConfirm.getText().toString();
                if(str1.length() < 6 || str2.length() < 6 || str3.length() < 6){
                    textTip.setText("密码长度不能小于6位数");
                    textTip.setVisibility(View.VISIBLE);
                }else if(mNetWorkUtils.getConnectState() == NetWorkUtils.NetWorkState.NONE){
                    textTip.setText("无可用网络");
                    textTip.setVisibility(View.VISIBLE);
                }else if(!str2.equals(str3)){
                    textTip.setText("新密码与确认密码不一致");
                    textTip.setVisibility(View.VISIBLE);
                }else {
                    finish();
                }
            }
        });
    }

    @Override
    protected void init() {
        titleBar.setLeft(true, R.drawable.arrow_back_white);
        titleBar.setTitleBarVisibility(true, "修改密码");
    }
}
